<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加工位</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i>
    首页
    <span class="c-gray en">&gt;</span>
    基础设置
    <span class="c-gray en">&gt;</span>
    工位类型配置
    <span class="c-gray en">&gt;</span>
    添加工位类型
</nav>
<div class="page-container">
    <div class="form-unit">基本信息</div>
    <form action="" method="post" class="form form-horizontal" id="basic-station-form-add">
        <div class="form-group">
            <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>工位类型名称：</label>
            <div class="formControls col-xs-3 col-sm-3">
                <input type="text" class="form-control" value="" placeholder="必填项" id="BasicStationAdd-storeName" name="storeName">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>工位类型：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <select type="text" class="form-control" id="BasicStationAdd-stationNumber" name="stationNumber" multiple="multiple"></select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input onclick="merchantBasicStationAddFun.submitAnaysis();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    /*工位类型配置，添加页面 merchantStoreStationAddAddFun*/
    var merchantBasicStationAddFun;

    merchantBasicStationAddFun={
        init : function () {
            let _this = this;
            _this.bootstrapvalidatorForm();
            //加载工位类型
            _this.workPositionType();

        },
        //提交
        submitAnaysis : function () {
            //bootstrap验证
            var bootstrapValidator = $("#basic-station-form-add").data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid())
                $("#basic-station-form-add").submit();
            else return;

            var positionType = '';
            var temp = $("#basic-station-form-add").serializeArray();
            for(var i =1;i<temp.length;i++){
                if(temp[i].name == 'stationNumber'){
                    if(positionType != ''){
                        positionType += ",";
                    }
                    positionType += temp[i].value;
                }
            }

            $.ajax({
                type: "GET",
                url: "biz/insertWorkPosition",
                data: {positionType:positionType,positionTypeName:$("#BasicStationAdd-storeName").val()},
                dataType: "json",
                success: function(data){
                    //state为true，新增成功
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //关闭新增窗口
                        removeIframe();

                        //刷新
                        $("#basicStationTable").bootstrapTable("refresh");
                    }

                },
                error:function () {
                    alert("error");
                }
            });
        },
        //加载工位类型
        workPositionType : function () {
            $.ajax({
                type: "GET",
                url: "sys/getTreeNodes",
                dataType: "json",
                success: function (data) {
                    $("#BasicStationAdd-stationNumber").select2({
                        data: data.data,
                        placeholder: '请选择工位类型',
                        width: '380px'
                    });
                },
                error: function () {
                    alert("error2");
                }
            });
        },
        //bootstrap验证
        bootstrapvalidatorForm: function () {
            $('#basic-station-form-add').bootstrapValidator({
                message: 'This value is not valid',
                excluded : [':disabled'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    storeName: {
                        validators: {
                            notEmpty: {
                                message: '工位类型名称不能为空'
                            },
                            stringLength: {
                                min: 2,
                                max: 50,
                                message: '工位类型名称长度必须在2到50位之间'
                            }
                        }
                    }
                }
            });
        }
    };

    merchantBasicStationAddFun.init();
</script>
</body>
</html>